package com.wicket.okrframework.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.common.util.RedisUtil;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.wicket.okrframework.base.service.MOrganizationService;
import com.wicket.okrframework.dal.po.mbg.Organization;
import com.wicket.okrframework.base.service.dto.req.QueryOrgDetailReq;
import com.wicket.okrframework.common.exception.Assert;
import com.wicket.okrframework.biz.service.RoleService;
import com.wicket.okrcomponent.integration.dto.GenerateDataObjectBatchCodeComRespDto;
import com.wicket.okrcomponent.integration.dto.GenerateDataObjectBatchCodeComReqDto;
import com.wicket.okrframework.biz.service.nb.NbDashboradStandardData;
import com.wicket.okrcomponent.integration.FwCompInterfaceModeClient;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@Service
public class DashboradStandardDataServiceImpl
  implements com.wicket.okrframework.biz.service.DashboradStandardDataService {

  @Resource
  private RedisUtil redisUtil;
@Resource
  private MOrganizationService mOrganizationService;
@Resource
  private RoleService roleService;
//@Resource
 //private MCustomFields2Service mCustomFields2Service;
@Resource
  private NbDashboradStandardData nbDashboradStandardData;
@Resource
  private FwCompInterfaceModeClient fwCompInterfaceModeClient;
/**
   * D1获取公共字段入参(公共)[8943]
   * gen by moon at 5/21/2024, 2:02:32 AM
   */
  @Trace(operationName = "D1获取公共字段入参(公共)")
  @Tags({@Tag(key = "参数",value = "arg[0]"),
            @Tag(key = "返回值",value = "returnedObj")})
  @Transactional(rollbackFor=Exception.class)
  @Override
  public ObtainCommonFieldRefComRespDto obtainCommonFieldRefCom(ObtainCommonFieldRefComReqDto reqDto){
    
      
      QueryReceiveFieldDetailRespDto receptionServiceRes_1 =null;
GenerateDataObjectBatchCodeComRespDto generateDataObjectBatchCodeComRespDto_1 =null;
      Organization organization_1 =null;
QuerySpaceManagerDetailComRespDto querySpaceManagerDetailComRespDto_1 =null;
//步骤0: M1-获取接收字段（特殊方法） - queryReceiveFieldDetail
     //ModelCode: receptionService
        QueryReceiveFieldDetailRespDto receptionServiceRes = null;
    QueryReceiveFieldDetailReqDto receptionServiceReq=new QueryReceiveFieldDetailReqDto();
  receptionServiceReq.setCalcStartTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME//sourceId:1811446_1

    /*M1获取计算开始时间[3715]  用于特殊方法接收上游入参。 */
    Assert.isNull(receptionServiceReq.getCalcStartTime(),"D1获取公共字段入参(公共)-M1获取计算开始时间-计算开始时间不能为空",false);
      receptionServiceRes = nbDashboradStandardData.queryReceiveFieldDetail(receptionServiceReq);


      receptionServiceRes_1 = receptionServiceRes;

//步骤1: D2生成数据对象批次标识(公共) - generateDataObjectBatchCodeCom
     GenerateDataObjectBatchCodeComRespDto generateDataObjectBatchCodeComRespDto = null;
    GenerateDataObjectBatchCodeComReqDto generateDataObjectBatchCodeComReqDto=new GenerateDataObjectBatchCodeComReqDto();


    /*D2生成数据对象批次标识(公共)[9404]   */

      generateDataObjectBatchCodeComRespDto = fwCompInterfaceModeClient.generateDataObjectBatchCodeCom(generateDataObjectBatchCodeComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


      generateDataObjectBatchCodeComRespDto_1 = generateDataObjectBatchCodeComRespDto;

//步骤2: 1-3-12查询组织详情 - queryOrgDetail
     Organization organization = null;
    QueryOrgDetailReq queryOrgDetailReq=new QueryOrgDetailReq();
  queryOrgDetailReq.setIsHighOrg("TRUE");//sourceId:1670969_1
queryOrgDetailReq.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1670986_1
if(reqDto!=null){
      queryOrgDetailReq.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1670970_1
    }
  
    /*1-3-12查询组织详情[201]   */
    Assert.isNull(queryOrgDetailReq.getIsHighOrg(),"D1获取公共字段入参(公共)-1-3-12查询组织详情-是否最高组织不能为空",false);
Assert.isNull(queryOrgDetailReq.getSubjectLifeCycle(),"D1获取公共字段入参(公共)-1-3-12查询组织详情-主体生命周期不能为空",false);
Assert.isNull(queryOrgDetailReq.getSpaceId(),"D1获取公共字段入参(公共)-1-3-12查询组织详情-创建于空间ID不能为空",false);
      organization = mOrganizationService.queryOrgDetail(queryOrgDetailReq)/*vcase invoke 本地 method 方法调用;*/;
      
      
      organization_1 = organization;
    
//步骤3: D1查询空间管理员(公共) - querySpaceManagerDetailCom
     QuerySpaceManagerDetailComRespDto querySpaceManagerDetailComRespDto = null;
    QuerySpaceManagerDetailComReqDto querySpaceManagerDetailComReqDto=new QuerySpaceManagerDetailComReqDto();
  if(reqDto!=null){
      querySpaceManagerDetailComReqDto.setSpaceId(reqDto.getSpaceId());//SimpleFieldAssign//sourceId:1671541_1
    }
  
    /*D1查询空间管理员(公共)[8945]   */
    Assert.isNull(querySpaceManagerDetailComReqDto.getSpaceId(),"D1获取公共字段入参(公共)-D1查询空间管理员(公共)-创建于空间ID不能为空",false);
      querySpaceManagerDetailComRespDto = roleService.querySpaceManagerDetailCom(querySpaceManagerDetailComReqDto)/*vcase invoke isSameApp*/;
      
      
      querySpaceManagerDetailComRespDto_1 = querySpaceManagerDetailComRespDto;
    
ObtainCommonFieldRefComRespDto retData = new ObtainCommonFieldRefComRespDto();
  if(receptionServiceRes_1!=null){
      retData.setCalcStartTime(receptionServiceRes_1.getCalcStartTime());//SimpleFieldAssign//sourceId:1811449_1
    }
if(generateDataObjectBatchCodeComRespDto_1!=null){
      retData.setDataObjectBatchCode(generateDataObjectBatchCodeComRespDto_1.getDataObjectBatchCode());//SimpleFieldAssign//sourceId:1811450_1
    }
  if(organization_1!=null){
      retData.setOrganizationId(organization_1.getOrganizationId());//SimpleFieldAssign//sourceId:1670989_1
    }
if(querySpaceManagerDetailComRespDto_1!=null){
      retData.setInductionRecordId(querySpaceManagerDetailComRespDto_1.getInductionRecordId());//SimpleFieldAssign//sourceId:1671544_1
    }
  

  
  
return retData;
  }
  //
}
